/*
 * @Description: file content
 */
const ProductService = require("../../services/admin/ProductService")
const ProductController = {
  add: async (req, res) => {
    const { introduction, detail, title, } = req.body
    const productImg = req.file ? `/productsupload/${req.file.filename}` : ''
    await ProductService.add({ introduction, detail, productImg, title })
    res.send({
      code: 200,
      msg: '添加成功',
    })
  },
  getList: async (req, res) => {
    const id = req.params.id
    const result = await ProductService.getList(id)
    res.send({
      code: 200,
      data: result,
      msg: '数据获取成功',
    })
  },
  delOne: async (req, res) => {
    const id = req.params.id
    await ProductService.delOne({ _id: id })
    res.send({
      code: 200,
      msg: '删除成功',
    })
  },
  updateOne: async (req, res) => {
    const { introduction, detail, title, _id } = req.body
    const productImg = req.file ? `/productsupload/${req.file.filename}` : ''
    await ProductService.updateOne({ _id, introduction, detail, title, productImg })
    res.send({
      code: 200,
      msg: '更新成功',
    })
  },
}
module.exports = ProductController
